//package com.example.project_springboot.filter;
//
//import com.alibaba.fastjson.JSONObject;
//import com.example.project_springboot.pojo.Result;
//import com.example.project_springboot.utils.JwtUtils;
//import org.springframework.context.annotation.Configuration;
//
//import javax.servlet.*;
//import javax.servlet.annotation.WebFilter;
//import javax.servlet.http.HttpServletRequest;
//import java.io.IOException;
//
////@WebFilter("/*")
//@Configuration
//public class UserFilter implements Filter {
//    @Override
//    public void init(FilterConfig filterConfig) throws ServletException {
//        Filter.super.init(filterConfig);
//    }
//    @Override
//    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
//        HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
//        String requestURI = httpServletRequest.getRequestURI();
//        boolean b = requestURI.contains("/loginAi");
//        if (!b){
//            String token = httpServletRequest.getHeader("token");
//            if (token != null) {
//                JwtUtils.parseJWT(token);
//                filterChain.doFilter(servletRequest, servletResponse);
//            }else {
//                Result error = Result.error("登录有误");
//                String s = JSONObject.toJSONString(error);
//
//                servletResponse.getWriter().write(s);
//            }
//        }
//        filterChain.doFilter(servletRequest,servletResponse);
//    }
//
//    @Override
//    public void destroy() {
//        Filter.super.destroy();
//    }
//}
